home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / ada / c01oop.zip / CPPWKBK / CPPV3-1.CPP < prev    next >
C/C++ Source or Header  |  1992-08-25  |  771b  |  45 lines

  1. #define HEADER "C++ Problem 3.1 by Rick Conn using Borland C++"
  2.  
  3. #include <stdio.h>
  4.  
  5. class counter {
  6.   static int object_count;
  7. public:
  8.   counter();
  9.   static int get_count(void);
  10. };
  11.  
  12. int counter::object_count = 0;  // init count
  13.  
  14. counter::counter() { counter::object_count++; }
  15.  
  16. int counter::get_count(void)
  17. {
  18.   return counter::object_count;
  19. }
  20.  
  21. void main(void)
  22. {
  23.   printf("%s\n", HEADER);
  24.  
  25.   counter c1;
  26.   printf("The count is %d\n",
  27.     c1.get_count());
  28.  
  29.   counter c2;
  30.   printf("The count is %d\n",
  31.     counter::get_count());
  32.  
  33.   counter c3;
  34.   printf("The count is %d\n",
  35.     c3.get_count());
  36.  
  37.   counter c4;
  38.   printf("The count is %d\n",
  39.     c4.get_count());
  40.  
  41.   counter c5;
  42.   printf("The count is %d\n",
  43.     c5.get_count());
  44. }
  45.